$execute as @s[tag=!smithingTable.itemSlot] run return run execute as @n[tag=smithingTable.itemSlot,type=item_display,distance=..500] at @s run function vs:system/game_ctrol/smithing_table/slot/place_item {UUID:$(UUID)}
$execute unless data entity @p[nbt={UUID:$(UUID)}] SelectedItem run return fail

$data modify entity @s item set from entity @p[nbt={UUID:$(UUID)}] SelectedItem
$item replace entity @p[nbt={UUID:$(UUID)}] weapon.mainhand with air

playsound entity.item_frame.add_item master @a ~ ~ ~ 1.0 1.0